package com.gcu.controller;

import com.gcu.pojo.loginInfo;
import com.gcu.service.impl.loginServiceImpl;
import com.gcu.service.impl.userInfoServiceImpl;
import com.gcu.service.loginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@CrossOrigin
@RequestMapping("/user")
public class UserController {

    @Autowired
    private loginService loginService;

    @Autowired
    private userInfoServiceImpl uerInfoService;

    //登录
    @PostMapping("/login")
    public Map<String,Object> login(loginInfo loginfo){
        Map<String,Object> res = new HashMap<>();
        res.put("userid",loginfo.getUserid());
        res.put("password",loginfo.getPassword());
        System.out.println(loginfo.getUserid()+" ---- "+loginfo.getPassword());
        res.put("登录状态","登录成功！");
        return res;
    }
    //登录测试
    @PostMapping("/login/user")
    public String login(HttpServletRequest request){
        String quert = request.getQueryString();
        String userid = request.getParameter("userid");
        String password = request.getParameter("password");
        loginInfo loginfo = new loginInfo(userid,password);
        boolean res = loginService.login(loginfo);

        System.out.println(res);

        System.out.println(userid+"密码"+password);
        return String.valueOf(res);
    }

    @GetMapping("/login/allUser")
    public List<loginInfo> loginInfoList(){
        System.out.println("访问接口");
        return loginService.selectAllLoginInfo();
    }


}
